import { createRouter, createWebHistory } from 'vue-router'

const cusColumn = () => import("@/views/CusColumn")
const Message = () => import("views/Message")
const page404 = ()
const About = { template: '<div>About</div>' }
const routes = [
  // {path:"/", redirect:"/home"},
  {
    path:"/cus-column",
    meta:{
      title:"Custom Column",
      role:"cus-column"
    },
    component:cusColumn
  },
  {
    path:"/message",
    meta:{
      title:"Custom Message",
      role:"cus-message"
    },
    component:Message
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes
})
router.beforeEach((to,from) => {
  document.title = to.meta.title
    ? to.meta.title + " | vue3Component"
    : " vue3Component";
  console.log(to,from)
  const roles = ["cus-message"]
  if(roles.includes(to.meta.role)) {
    return true;
  } else {
    router.push("/404")
  }
})
export default router